#!/usr/bin/env python

import threading,commands,sys

def runcheck(command,monitor):
    global result
    status,output = commands.getstatusoutput(command)
    status = status >> 8
    if status == 0:
        result[monitor]['status'] = 'Ok'
    else:
        result[monitor]['status'] = 'Bad'
    result[monitor]['info'] = output

try:
    param = sys.argv[1]
except:
    print '<check_master> Recv param error.'
    sys.exit()

dir = sys.path[0]
threads = []
result = {} 
for i in param.split('.'):
    if i:
        monitor,command = i.split(':')
        result[monitor] = {}
        threads.append(threading.Thread(target=runcheck,args=('%s/%s' % (dir,command),monitor)))
for t in threads:
    t.start()
for t in threads:
    t.join()
print result

